//
//  YCSellRightTableViewCell.m
//  YCVillageDoctor
//
//  Created by zhangxiaoliang on 2017/6/30.
//  Copyright © 2017年 zhangxiaoliang. All rights reserved.
//

#import "YCSellRightTableViewCell.h"
#import "YCSellRightModel.h"
#import "RFAlertView.h"

@interface YCSellRightTableViewCell()
//卡名称
@property(nonatomic,strong)UILabel *nameLabel;
//卡左边的缩略图
@property(nonatomic,strong)UIImageView *iconImage;
//卡上面和下面的描述
@property(nonatomic,strong)UILabel *descLabelT;
@property(nonatomic,strong)UILabel *descLabelB;
//二维码的图片
@property(nonatomic,strong)UIButton *iconQrcode;

@property(nonatomic,strong)UIView *lineView;
@end

@implementation YCSellRightTableViewCell
- (void)setModel:(YCSellRightModel *)model
{
    _model = model;
    model.CARD_NAME = [model.CARD_NAME stringByAppendingString:@"\n"];
    NSMutableAttributedString *attributedString =  [[NSMutableAttributedString alloc] initWithString:model.CARD_NAME attributes:@{NSKernAttributeName : @(1.5f)}];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:7];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, model.CARD_NAME.length)];
    [self.descLabelT setAttributedText:attributedString];
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:model.CARD_PIC] placeholderImage:[UIImage imageNamed:@"loginIcon"]];
    //self.descLabelB.text = model.SHOW_DESC;

}
- (void)setIsShowLine:(NSInteger)isShowLine
{
    _isShowLine = isShowLine;
    self.lineView.hidden = isShowLine;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        
        self.backgroundColor = RGB(247, 247, 249);
  
        UIImageView *iconImage = [[UIImageView alloc]init];
        self.iconImage = iconImage;
        iconImage.layer.cornerRadius = 3;
        iconImage.layer.masksToBounds = YES;
        [self.contentView addSubview:iconImage];
        
        UILabel *descLabelT  = [[UILabel alloc]init];
        self.descLabelT = descLabelT;
        descLabelT.backgroundColor = [UIColor clearColor];
        descLabelT.textColor = RGB(163, 163, 163);
        descLabelT.numberOfLines = 0;
        descLabelT.font = [UIFont systemFontOfSize:14];
        

        
        [self.contentView addSubview:descLabelT];
        
        
        UIView *lineView = [[UIView alloc]init];
        self.lineView = lineView;
        lineView.backgroundColor = RGB(224, 224, 224);
        [self.contentView addSubview:lineView];
        
        
        
//        UILabel *descLabelB  = [[UILabel alloc]init];
//        self.descLabelB = descLabelB;
//        descLabelB.backgroundColor = [UIColor clearColor];
//        descLabelB.textColor = RGB(163, 163, 163);
//        descLabelB.numberOfLines = 0;
//        descLabelB.font = [UIFont systemFontOfSize:14];
//        [self.contentView addSubview:descLabelB];

        UIButton *iconQrcode = [[UIButton alloc]init];
        [iconQrcode addTarget:self action:@selector(qrBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.iconQrcode = iconQrcode;
        [self.contentView addSubview:iconQrcode];
        [self.iconQrcode setImage:[UIImage imageNamed:@"百倍爱心卡宣传-弹窗_03"] forState:UIControlStateNormal];
        __weak __typeof(&*self)mySelf = self;
        
   
        
        [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(mySelf.contentView.mas_top).mas_offset(10);
            make.left.mas_equalTo(mySelf.contentView.mas_left).mas_offset(5);
            make.width.mas_equalTo(70);
            make.height.mas_equalTo(50);
        }];
        
        
        [descLabelT mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(iconImage.mas_top).mas_offset(0);
            make.left.mas_equalTo(iconImage.mas_right).mas_offset(5);
            make.right.mas_equalTo(mySelf.contentView.mas_right).mas_offset(-40);
            make.height.mas_equalTo(50);
        }];
        
//        [descLabelB mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.mas_equalTo(descLabelT.mas_bottom).mas_offset(5);
//            make.left.mas_equalTo(iconImage.mas_right).mas_offset(5);
//            make.right.mas_equalTo(mySelf.contentView.mas_right).mas_offset(-40);
//            make.height.mas_equalTo(22);
//        }];
        
        [iconQrcode mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(descLabelT.mas_top).mas_offset(0);
            make.right.mas_equalTo(mySelf.contentView.mas_right).mas_offset(-5);
            make.width.mas_equalTo(25);
            make.height.mas_equalTo(25);
        }];
        
        
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.mas_equalTo(mySelf.contentView.mas_left).mas_offset(5);
            make.right.mas_equalTo(mySelf.contentView.mas_right).mas_offset(0);
            make.height.mas_equalTo(1);
            make.bottom.mas_equalTo(mySelf.contentView.mas_bottom).mas_offset(-1);
        }];
        
        
    }
    return self;
}
- (void)qrBtnClick:(UIButton *)btn
{
    btn.userInteractionEnabled = NO;
    [DownloadData post:kGetQRCodeInfo params:@{@"expert_id":[YCUserTool sharedTools].expertID} success:^(id json) {
           
            NSString *strS = [NSString stringWithFormat:@"%@&user_id=%@&user_name=%@&link_mobile=%@",self.model.SKIP_TO,json[@"user_id"],[json[@"user_name"] hdf_base64Encoding],json[@"link_mobile"]];
            [[RFAlertView sharedAlertView]showAlertViewWithQRStr:strS andBlock:^{
                btn.userInteractionEnabled = YES;
            }];
    } failure:^(NSError *error) {
        
    }];

}
@end
